// 创建测试用户的工具函数
export const createTestUser = () => {
  const testUser = {
    id: '1',
    username: 'admin',
    password: '123456',
    name: '管理员',
    gender: 'male' as const,
    avatar: '',
    phone: '13800138000',
    email: 'admin@example.com',
    createdAt: new Date().toISOString(),
    roles: ['admin', 'user'],
    permissions: ['read:home', 'read:stocks', 'write:stocks', 'admin:all'],
  };

  // 检查是否已有用户数据
  const existingUsers = JSON.parse(localStorage.getItem('users') || '[]');
  
  // 如果没有admin用户，则添加
  if (!existingUsers.some((u: any) => u.username === 'admin')) {
    existingUsers.push(testUser);
    localStorage.setItem('users', JSON.stringify(existingUsers));
    console.log('测试用户已创建：');
    console.log('用户名: admin');
    console.log('密码: 123456');
    console.log('手机号: 13800138000');
  }
};

// 在开发环境下自动创建测试用户
if (import.meta.env.DEV) {
  createTestUser();
}